package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.mall.api.entity.MallOrderCouponDetailModel;
import com.mallcloud.mall.mall.service.MallOrderCouponDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-券订单明细")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/orderCouponDetail")
public class MallOrderCouponDetailController {
    private final MallOrderCouponDetailService orderCouponDetailService;

    @ApiOperation("分页")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupondetail_view')")
    public R<IPage<MallOrderCouponDetailModel>> page(Page page, MallOrderCouponDetailModel orderModel) {
        return R.ok(orderCouponDetailService.page(page, Wrappers.lambdaQuery(orderModel)));
    }

    @ApiOperation("列表")
    @GetMapping("/list")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupondetail_view')")
    public R<List<MallOrderCouponDetailModel>> list(MallOrderCouponDetailModel orderModel) {
        return R.ok(orderCouponDetailService.list(Wrappers.query(orderModel)));
    }

    @ApiOperation("查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupondetail_view')")
    public R<MallOrderCouponDetailModel> getById(@PathVariable("id") String id) {
        return R.ok(orderCouponDetailService.getById(id));
    }

    @ApiOperation("新增")
	@PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupondetail_add')")
    public R<Boolean> save(@RequestBody MallOrderCouponDetailModel orderModel) {
		return R.ok(orderCouponDetailService.save(orderModel));
    }

    @ApiOperation("修改")
	@PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupondetail_edit')")
    public R<Boolean> updateById(@RequestBody MallOrderCouponDetailModel orderModel) {
        return R.ok(orderCouponDetailService.updateById(orderModel));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_ordercoupondetail_del')")
    public R<Boolean> removeById(@PathVariable Long id) {
        return R.ok(orderCouponDetailService.removeById(id));
    }

}
